package com.Rest2Go;

import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Gallery;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.Rest2Go.R.menu;
import com.Rest2Go.Utils.Utils;

public class NewMenuDataAdapter extends BaseAdapter
{

	private ArrayList<String>	mArr;
	private Context				mContext;
	private MoveEatGallery		mViewGallery;
	private MoveEatGallery		mMenuGallery;

	public NewMenuDataAdapter(ArrayList<String> array, Context context, MoveEatGallery gallery, MoveEatGallery menuGallery)
	{
		mArr = array;
		mContext = context;
		mViewGallery = gallery;
		mMenuGallery = menuGallery;
	}

	public void add(String item)
	{
		mArr.add(item);

	}

	@Override
	public int getCount()
	{
		return mArr.size();
	}

	@Override
	public Object getItem(int pos)
	{
		return mArr.get(pos);
	}

	@Override
	public long getItemId(int id)
	{
		return id;
	}

	@Override
	public View getView(int pos, View convertView, ViewGroup parent)
	{
		LinearLayout menuView;
		try
		{
			
//				mMenuGallery.setBeingUpdated(false);
//				mViewGallery.setBeingUpdated(true);
//				mViewGallery.setAnimationDuration(500);
//				mViewGallery.setSelection(pos, true);
//			
		}
		catch (IndexOutOfBoundsException ex)
		{
			// mGallery.setSelection(pos,true);
			Utils.log("waiting for gallery to be index");
		}
		if (convertView == null)
		{
			menuView = new LinearLayout(mContext);
			LayoutInflater vi = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			vi.inflate(R.layout.menu_item, menuView, true);
		}
		else
		{
			menuView = (LinearLayout) convertView;
		}
		TextView txt = (TextView) menuView.findViewById(R.id.menu_item_text);
		txt.setText(mArr.get(pos));

		return menuView;
	}

}
